package com.atguigu.common.execption;

import com.atguigu.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * @author Jason Gong
 * @version 1.0
 * @Date 2025/2/25
 * @Website https://qingling.icu
 * @Description 自定义异常类
 */
@Data
public class GuiguException extends RuntimeException {

    //状态码
    private Integer code;
    //描述信息
    private String message;

    /**
     * 通过状态码和错误消息创建异常对象
     */
    public GuiguException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 接收枚举类型对象
     */
    public GuiguException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }

    @Override
    public String toString() {
        return "GuiguException{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}